package com.xiyu.service.service.setting;

import com.xiyu.service.vo.setting.globalSetting.GlobalSettingUpdateInput;
import com.xiyu.service.repository.setting.global.SettingGlobalRepository;
import com.xiyu.service.vo.setting.globalSetting.GlobalSettingQueryByClassOutput;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import org.springframework.transaction.annotation.Transactional;
import com.xiyu.service.util.entity.EntityUtils;
import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.convert.setting.GlobalSettingConvert;

import static com.xiyu.service.framework.exception.util.ServiceExceptionUtil.exception;

/**
 * 全局设置 Service 实现类
 */
@Service
@Validated
public class GlobalSettingServiceImpl implements GlobalSettingService {

    @Resource
    SettingGlobalRepository settingGlobalRepository;

    @Override
    public List<GlobalSettingQueryByClassOutput> queryByClass(String settingClass) {
        return GlobalSettingConvert.INSTANCE.queryByClassOutputConvert(settingGlobalRepository.findBySettingClass(settingClass));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean update(List<GlobalSettingUpdateInput> inputVO) {
        for(GlobalSettingUpdateInput input : inputVO){
            settingGlobalRepository.updateSetting(input.getSettingKey(), input.getSettingValue());
        }
        return true;
    }

}
